home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / PowerPlant / Everything / CStuff.cp < prev    next >
Encoding:
Text File  |  1998-10-11  |  5.9 KB  |  253 lines  |  [TEXT/CWIE]

  1. // CStuff.cp -- window methods
  2.  
  3. #include "CStuff.h"
  4.  
  5. #include <UEnvironment.h>
  6. #include <UReanimator.h>
  7. #include <URegistrar.h>
  8. #include <LStream.h>
  9. #include <LTabGroup.h>
  10. #include <CustomControls.h>
  11. #include <LTextGroupBox.h>
  12. #include <LAMControlViewImp.h>
  13. #include <LGATextGroupBoxImp.h>
  14. #include <LPopupButton.h>
  15. #include <LAMPopupButtonImp.h>
  16. #include <LGAPopupButtonImp.h>
  17. #include <LScrollerView.h>
  18. #include <LScrollBar.h>
  19. #include <LAMTrackActionImp.h>
  20. #include <LStdScrollBarImp.h>
  21. #include <LTextTableView.h>
  22. #include <LCellSizeToFit.h>
  23. #include <LTextArray.h>
  24. #include <LTableArrayStorage.h>
  25. #include <UAttachments.h>
  26. #include <LTableMonoGeometry.h>
  27. #include <LTableSingleSelector.h>
  28. #include <CTextUtils.h>
  29.  
  30. #include "DDocData.h"
  31. #include "DModalCheckboxesData.h"
  32. #include "DModalRadiosData.h"
  33. #include "DModalTextData.h"
  34. #include "DModalStuffData.h"
  35. #include "DModalBarsData.h"
  36. #include "DModelessCheckboxesData.h"
  37. #include "DModelessRadiosData.h"
  38. #include "DModelessTextData.h"
  39. #include "DModelessStuffData.h"
  40. #include "DModelessBarsData.h"
  41. #include "EverythingCmds.h"
  42.  
  43. const MessageT    msgTools    = 'Toos';
  44. const MessageT    msgFromValuesList2    = 'Fro2';
  45. const MessageT    msgFromMenu    = 'Frou';
  46. const MessageT    msgTextList    = 'Text';
  47.  
  48. #define PPob_StuffID    205
  49. #define RidL_StuffID    205
  50.  
  51. Boolean        CStuff::sIsRegistered = false;
  52.  
  53. //----------
  54. CStuff*        CStuff::CreateStuff (
  55.     LCommander*        inSuperCommander,
  56.     DDocData*        inData)
  57. {
  58.     if (!sIsRegistered) {
  59.         RegisterClass ();
  60.     }
  61.  
  62.     CStuff*        window;
  63.     window = (CStuff *)LWindow::CreateWindow(PPob_StuffID, inSuperCommander);
  64.     window->ConnectToData (inData);
  65.     return window;
  66. }
  67.  
  68. //----------
  69. #define    RegisterClasses(AbstractClass,AMImpClass,GAImpClass)    \
  70.     RegisterClass_(AbstractClass);    \
  71.     if (useAppearance) {    \
  72.         RegisterClassID_(AMImpClass, AbstractClass::imp_class_ID);    \
  73.     } else {    \
  74.         RegisterClassID_(GAImpClass, AbstractClass::imp_class_ID);    \
  75.     }
  76.  
  77. //----------
  78. void    CStuff::RegisterClass ()
  79. {
  80.     Boolean        useAppearance = UEnvironment::HasFeature (env_HasAppearance);
  81.  
  82.     RegisterClass_(CStuff);
  83.  
  84.     // register the pane classes we use
  85.     RegisterClasses (CControlPane, CustomControlImp, CustomControlImp);
  86.     RegisterClasses (LTextGroupBox, LAMControlViewImp, LGATextGroupBoxImp);
  87.     RegisterClasses (LPopupButton, LAMPopupButtonImp, LGAPopupButtonImp);
  88.     RegisterClass_(LScrollerView);
  89.     RegisterClasses (LScrollBar, LAMTrackActionImp, LStdScrollBarImp);
  90.     RegisterClass_(LTextTableView);
  91.  
  92.     sIsRegistered = true;
  93. }
  94.  
  95. //----------
  96. CStuff::CStuff (
  97.     LStream*    inStream)
  98.     : LWindow (inStream)
  99. {
  100. }
  101.  
  102. //----------
  103. CStuff::~CStuff ()
  104. {
  105. }
  106.  
  107. //----------
  108. //    This member function gets called once the containment hierarchy that contains
  109. //    this pane has been built. It gives us a chance to get data members for
  110. //    interesting subviews, and to do other operations now that our subviews exist.
  111. void    CStuff::FinishCreateSelf ()
  112. {
  113.     mToolsPalette = (CControlPane*) FindPaneByID ('Toos');
  114.  
  115.     mFromValuesList2Popup = (LPopupButton*) FindPaneByID ('Fro2');
  116.  
  117.     mFromMenuPopup = (LPopupButton*) FindPaneByID ('Frou');
  118.  
  119.     mTextListTable = (LTextTableView*)FindPaneByID ('Text');
  120.     mTextListTable->AddListener(this);  // not a control so can't be included in RidL
  121.     mTextListTable->SetCellSizer (new LCellSizeToFit ());
  122.     mTextListTable->AddAttachment(new LEraseAttachment());
  123.     mTextListTable->SetTableGeometry(new LTableMonoGeometry(mTextListTable, 
  124.                             68 /* col width */, 
  125.                             11  /* row height */));
  126.     mTextListTable->SetTableSelector(new LTableSingleSelector(mTextListTable));
  127. // use LTextArray to contain list items
  128.     LTextArray* mTextListTableArray = new LTextArray;
  129.     *mTextListTableArray += "One";
  130.     *mTextListTableArray += "Two";
  131.     *mTextListTableArray += "Three";
  132.     *mTextListTableArray += "Infinity";
  133.     mTextListTable->SetTableStorage(new LTableArrayStorage(mTextListTable, mTextListTableArray));
  134.  
  135.  
  136.     UReanimator::LinkListenerToControls(this, this, RidL_StuffID);
  137.         // "connect" self to our controls that we want to "listen" to
  138.  
  139.     // any additional initialization for your window:
  140. }
  141.  
  142. //----------
  143. void    CStuff::ConnectToData (
  144.     DDocData*        inData)
  145. {
  146.     mData = inData;
  147.     mData->AddListener (this);
  148.  
  149.     mToolsPalette->SetValue (mData->GetTools ());
  150.     mFromValuesList2Popup->SetValue (mData->GetFromValuesList2 ());
  151.     mFromMenuPopup->SetValue (mData->GetFromMenu ());
  152.     mTextListTable->SetValue (mData->GetTextList ());
  153. }
  154.  
  155. //----------
  156. void    CStuff::DataChanged (
  157.     long        inDataID)
  158. {
  159.     StopListening ();
  160.  
  161.     if (inDataID == idTools) {
  162.         mToolsPalette->SetValue (mData->GetTools ());
  163.     }
  164.     if (inDataID == idFromValuesList2) {
  165.         mFromValuesList2Popup->SetValue (mData->GetFromValuesList2 ());
  166.     }
  167.     if (inDataID == idFromMenu) {
  168.         mFromMenuPopup->SetValue (mData->GetFromMenu ());
  169.     }
  170.     if (inDataID == idTextList) {
  171.         mTextListTable->SetValue (mData->GetTextList ());
  172.     }
  173.  
  174.     StartListening ();
  175. }
  176.  
  177. //----------
  178. void    CStuff::ListenToMessage (
  179.     MessageT    inMessage,
  180.     void*        ioParam)
  181. {
  182.     switch (inMessage) {
  183.     case msgDataChanged:
  184.             DataChanged ((long)ioParam);
  185.         break;
  186.  
  187.     case msgTools:
  188.             mData->SetTools (mToolsPalette->GetValue ());
  189.         break;
  190.  
  191.     case msgFromValuesList2:
  192.             mData->SetFromValuesList2 (mFromValuesList2Popup->GetValue ());
  193.         break;
  194.  
  195.     case msgFromMenu:
  196.             mData->SetFromMenu (mFromMenuPopup->GetValue ());
  197.         break;
  198.  
  199.     case msgTextList:
  200.             mData->SetTextList (mTextListTable->GetValue ());
  201.         break;
  202.  
  203.     default:
  204.           ; // do something
  205.         break;
  206.     }
  207. }
  208.  
  209. //----------
  210. Boolean        CStuff::ObeyCommand (
  211.     CommandT    inCommand,
  212.     void*        ioParam)
  213. {
  214.     Boolean        cmdHandled = true;
  215.  
  216.     if (inCommand < 0) {
  217.         // modal dialog has finished
  218.  
  219.         switch (-inCommand) {
  220.         }
  221.  
  222.     } else {
  223.         switch (inCommand) {
  224.  
  225.         default:
  226.                 cmdHandled = LWindow::ObeyCommand(inCommand, ioParam);
  227.             break;
  228.         }
  229.     }
  230.  
  231.     return cmdHandled;
  232. }
  233.  
  234. //----------
  235. void    CStuff::FindCommandStatus (
  236.     CommandT    inCommand,
  237.     Boolean        &outEnabled,
  238.     Boolean        &outUsesMark,
  239.     Char16        &outMark,
  240.     Str255        outName)
  241. {
  242.     outUsesMark = false;
  243.  
  244.     switch (inCommand) {
  245.  
  246.  
  247.     default:
  248.             LWindow::FindCommandStatus(inCommand, outEnabled,
  249.                                         outUsesMark, outMark, outName);
  250.         break;
  251.     }
  252. }
  253.